// index.js
import {
  get,
  post
} from '../../utils/request'
import {
  APIS
} from '../../utils/api'
import {
  timestampToTime
} from '../../utils/util'
// 获取应用实例
const app = getApp()

Page({
  data: {
    tabs: [{
      name: '消费记录',
      val: 'orderList'
    }, {
      name: '充值记录',
      val: 'paymentList'
    }, {
      name: '卡券记录',
      val: 'discountList'
    }],
    tabIndex: 0,
    infoList: [{
        name: '首次到店',
        value: '0000.00.00 00:00'
      },
      {
        name: '上次消费时间:',
        value: '0000.00.00 00:00'
      },
      {
        name: '会员余额:',
        value: '1000.00元'
      },
      {
        name: '优惠券:',
        value: '0张'
      },
      {
        name: '充值金额:',
        value: '500.00元'
      },
      {
        name: '累计营业金额:',
        value: '500.00元'
      }
    ],
    headerTitle: [
      [{
        name: '消费日期',
        key: 'endTime'
      }, {
        name: '开台类型',
        key: 'type'
      }, {
        name: '划卡金额',
        key: 'payment'
      },
      // {
      //   name: '结算金额',
      //   key: 'realPay'
      // }
    ],
      [{
        name: '充值日期',
        key: 'date'
      }, {
        name: '充值金额',
        key: 'price'
      }, {
        name: '赠送金额',
        key: 'intro'
      }, {
        name: '卡内余额',
        key: 'type'
      }],
      [{
        name: '卡券类型', // todo
        key: 'type'
      }, {
        name: '卡券内容',
        key: 'getDate'
      }, {
        name: '有效日期',
        key: 'alias'
      }, {
        name: '是否使用',
        key: 'usedDate'
      }]
    ],
    listData: {
      paymentList: [],
      orderList: [],
      discountList: []
    },
    id: '',
    shop: '',
    shopname: '',
    userInfo: {}
  },
  onLoad(options) {
    const shopList = wx.getStorageSync('shopList');
    const shopInfo = shopList.find(v => +v.id === +options.shop)
    this.setData({
      id: options.id,
      shop: options.shop,
      shopname: shopInfo.name
    }, () => {
      this.getDetail();
    })
  },
  getDetail() {
    get(`${APIS.vip}/detail`, {
        luid: this.data.id,
        shop: this.data.shop
      })
      .then(res => {
        this.setData({
          ...res.data
        })
      })
  },
  handleChange(e) {
    const {
      index
    } = e.target.dataset;
    this.setData({
      tabIndex: index,
    });
  },
})